package view.components;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.BevelBorder;

@SuppressWarnings("serial")
public class StatusBar extends JPanel {

	private StatusPane userPane;
	private StatusPane userRolePane;
	private StatusPane usersCompany;
	private StatusPane datePane;
	
	public StatusBar() {
		init();
	}
	
	public void init() {
		setLayout(new GridLayout(1,3,5,5));
		setBorder(BorderFactory.createLineBorder(Color.white));
		setBackground(Color.GRAY);

		userPane = new StatusPane("");
		
		userRolePane = new StatusPane("");
		
		usersCompany = new StatusPane("");
		
		SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
		String dateString = sdf.format(new Date());
		datePane = new StatusPane(dateString);
		
		
		add(userPane);
		add(userRolePane);
		add(usersCompany);
		add(datePane);
	}
	
	public void setUsername(String username) {
		userPane.setText(username);
	}
	
	public void setRoleName(String roleName) {
		userRolePane.setText(roleName);
	}

	public void setUsersCompany(String company) {
		usersCompany.setText(company);
	}
	
	public void clearPanes() {
		userPane.setText("");
		userRolePane.setText("");
		usersCompany.setText("");
	}
	
	class StatusPane extends JLabel{
		public StatusPane(String text) {
			setText(text);
			setHorizontalAlignment(CENTER);
			setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			setPreferredSize(new Dimension(200,25));			
		}
	}

	public StatusPane getUserPane() {
		return userPane;
	}

	public void setUserPane(StatusPane userPane) {
		this.userPane = userPane;
	}

	public StatusPane getDatePane() {
		return datePane;
	}

	public void setDatePane(StatusPane datePane) {
		this.datePane = datePane;
	}

	public StatusPane getUserRolePane() {
		return userRolePane;
	}

	public void setUserRolePane(StatusPane userRolePane) {
		this.userRolePane = userRolePane;
	}

	public StatusPane getUsersCompany() {
		return usersCompany;
	}

	public void setUsersCompany(StatusPane usersCompany) {
		this.usersCompany = usersCompany;
	}

}
